/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package session;

import cart.ShoppingCart;
import entity.CustomerOrderHasProduct;
import java.util.List;
import java.util.Random;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Lisha
 */
@Stateless
public class CustomerOrderHasProductFacade extends AbstractFacade<CustomerOrderHasProduct> {
    @PersistenceContext(unitName = "emangaPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public CustomerOrderHasProductFacade() {
        super(CustomerOrderHasProduct.class);
    }
    
    public void insertCustomerOrderHasProduct(int customerOrderId, int productId, int quantity)
    {        
        em.createNativeQuery("INSERT INTO customer_order_has_product VALUES (" + customerOrderId + ", " + productId + ", " + quantity + ")").executeUpdate();
    }
    
        
    public List<Integer> findProductByCount() {
        Query q = em.createNamedQuery("CustomerOrderHasProduct.findProductByCount");
        return q.getResultList();
    }
    
    public List<CustomerOrderHasProduct> findByCustomerOrderId(int i) {
        Query q = em.createNamedQuery("CustomerOrderHasProduct.findByCustomerOrderId");
        q.setParameter("customerOrderId", i);
        return q.getResultList();
    }
    
}
